#pragma once
#ifndef Y_WINDOW_
#define Y_WINDOW_
#include <windows.h>
#include <tchar.h>
#include <string>
#include <memory>

#include "ConsoleLog.h"


//deprecated  use SDL2 instead
class YWindow
{
public:
	YWindow();
	virtual ~YWindow();

	bool Create();
	bool Destroy();
	bool IsWindow();
	HWND Handle() const { return m_hWnd; }
	bool PreTranslateMessage(MSG* msg);

	class Renderer {
	public:
		Renderer();
		virtual ~Renderer();

		const BITMAPINFO& GetBmi() const { return m_bmi; }
		const uint8_t* GetBmiData() const { return m_pBmiData.get(); }
		bool SetSize(int width, int height);
		int OnFrame(uint8_t* rgb_data, int width, int height);
	protected:
		BITMAPINFO m_bmi;
		std::unique_ptr<uint8_t> m_pBmiData;
		CRITICAL_SECTION buffer_lock_;
		int n;
	};

	Renderer* GetRenderer() { return m_pRenderer; };

protected:
	HWND m_hWnd;
	static ATOM wnd_class_;
	bool m_bDestroyed;
	void* m_msg;
	Renderer* m_pRenderer;

	static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
	static bool RegisterWindowClass();

	void OnDestroyed();
	bool OnMessage(UINT msg, WPARAM wp, LPARAM lp, LRESULT* result);
	void OnPaint();
};

#endif //Y_WINDOW_

